<%-- 
    Document   : login
    Created on : May 23, 2014, 10:32:35 AM
    Author     : tuanna
--%>

<%@page import="dao.DataAccess"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="dao.customerDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login Page</title>
    </head>
    <%
        customerDAO u = new customerDAO();
        String username="";
        String password="";
        String warning="";
        
        if(request.getParameter("username") != null && request.getParameter("password") != null){
            username=request.getParameter("username");
            password=request.getParameter("password");
            ResultSet rs=u.getData("select password from Customer where username='"+username+"'");
            
            if(!rs.next()){
                warning="USERNAME DOESN'T EXSIT !";
            }else if(!rs.getString(1).equals(password)){
                warning="WRONG PASSWORD !";
            }else {
                session=request.getSession(true);
                session.setAttribute("account", username);
                response.sendRedirect("ShowProduct.jsp");
            }
        }
    %>
    <body>
        <form action="login.jsp">
                        <table align="center" border="0">
                <tr>
                    <td width="50%"><b>UserName:</b> 
                    <td><input type="text" name="username" value="<%=username%>"/>
                </tr>
                <tr>
                    <td><b>Password:</b> 
                    <td><input type="password" name="password" value="<%=password%>"/>
                </tr>
                <tr>
                    <td height="20">
                </tr>
                <tr>
                    <td align="center" colspan="2"><input type="submit" value="Login"></td>
                </tr>
                <tr>
                    <td align="center" colspan="2"><font color="red"><%=warning%></font></td>
                </tr>
            </table>
        </form>
    </body>
</html>
